package io.kiki.sba.registry.server.data_store.remoting;

import io.kiki.sba.registry.api.ChannelHandler;
import io.kiki.sba.registry.api.exchange.DataExchanger;
import io.kiki.sba.registry.server.data_store.bootstrap.ServerConfig;
import io.kiki.sba.registry.server.shared.constant.CentralControlLeaderLearnModeEnum;
import io.kiki.sba.registry.server.shared.meta.AbstractCentralControlLeaderExchanger;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import java.util.Collection;


public class DataCentralControlServerManager extends AbstractCentralControlLeaderExchanger {

    @Autowired
    private ServerConfig serverConfig;

    @Resource(name = "metaClientHandlers")
    private Collection<ChannelHandler> metaClientHandlers;

    public DataCentralControlServerManager() {
        super(DataExchanger.META_SERVER_TYPE);
    }

    @Override
    protected CentralControlLeaderLearnModeEnum getMode() {
        if (defaultCommonConfig.isJdbc()) {
            return CentralControlLeaderLearnModeEnum.jdbc;
        } else {
            return CentralControlLeaderLearnModeEnum.loadbalancer;
        }
    }

    @Override
    protected Collection<String> getCentralControlServerDomains(String dataCenter) {
        return serverConfig.getMetaServerAddresses();
    }

    @Override
    public int getRpcTimeoutMillis() {
        return serverConfig.getRpcTimeoutMillis();
    }

    @Override
    public int getServerPort() {
        return serverConfig.getMetaServerPort();
    }

    @Override
    protected Collection<ChannelHandler> getClientHandlers() {
        return metaClientHandlers;
    }


}
